<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Cache;

class Login  {

    public function index() {
    	$username = $_POST['username'];
        $password = md5($_POST['password']);
        $data = Db::table('yhq_user')->where([['username','=',$username],['password','=',$password]])->find();
        $result;
        if(!empty($data)) {
            Cache::set('uid', $data['id'], 36000);
            $result=array('success'=>true,'username'=>$data['username']);
            $sql = array(
                'uid'=>$data['id'],
                'login_time'=>time(),
                'login_ip'=>$_SERVER['REMOTE_ADDR']
            );
            Db::table('yhq_login_log')->insert($sql);
        } else {
            $result=array('success'=>false,'message'=>'用户不存在');
        }        
        print_r(json_encode($result));
    }
}
